package com.user.controller;

import com.user.client.UserClient;
import com.user.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("web_user")
public class UserController {

//    @Autowired
//    public RestTemplate restTemplate;
//    @Autowired
//    private DiscoveryClient discoveryClient;

    @Autowired
    private UserClient userClient;


    @GetMapping
    @ResponseBody
    public User queryUserById(@RequestParam("id") Long id) {
//        List<ServiceInstance> instances = discoveryClient.getInstances("service-provider");
//        ServiceInstance serviceInstance = instances.get(0);
//        return this.restTemplate.getForObject("http://localhost:8080/user/" + id,User.class);  // 不要采取硬编码，
//        return this.restTemplate.getForObject("http://"+serviceInstance.getHost()+":"+serviceInstance.getPort() +"/user/"+id,User.class);
        return this.userClient.queryUserById(id);

    }


}
